tblObjectListIgnoreByName = {
	-- Names
	"Dreadspinner Egg",
	"Creeper Egg",
	"Manifestation",
	"Kor'kron Cannon",
	"Spike Mine",
	"Defias Cannon",
	"Mining Powder",
	"Manifestation",
	"Risen Zombie",
	"Lesser Volatile Energy",
	"Atal'ai Deathwalker's Spirit",
	"Burning Spirit",
	"Fanged Pit Viper",
}
tblObjectListIgnoreByType = {
	-- Creature Types
	"Critter",
	"Critter nil",
	"Wild Pet",
	"Pet",
	"Totem",	
}
ccrObjectListTable = {}
ccrLootTable = {}
tblPGetNearbyEnemies = {}
tblPGetMeleeEnemies = {}
--tblPEnemiesWithin10Yards = {}
--tblPEnemiesWithin12Yards = {}
--tblPEnemiesWithin16Yards = {}

ccR_Last_AutoLoot_Scanned = 0.1
ccR_Last_Units_Scanned = 0.1
ccR_Last_ObjectList_Scanned = 0.1
function ccR_GatherObjectList()
	if UnitIsDeadOrGhost("Player") == nil 
	and GObjectList
	and GObjectList == "ccR"
	and (GetTime() - ccR_Last_ObjectList_Scanned) >= 0.20
	then
		--[[
			OBJECT LIST
		]]
		table.empty(ccrObjectListTable)
		-- Gather UNIT
		local vObjCount = GetTotalObjects(TYPE_UNIT)
		for x = 1, vObjCount do
			-- Units
			local obj = GetObjectListEntry(x)
			table.insert(ccrObjectListTable, obj)	
		end
		-- Gather PLAYER
		vObjCount = GetTotalObjects(TYPE_PLAYER)
		for x = 1, vObjCount do
			local obj = GetObjectListEntry(x)
			table.insert(ccrObjectListTable, obj)	
		end
		--[[
			PLAYERS / ENEMIES
		]]
		if (ccrStart or ccRS.Debug)
		and (GetTime()-ccR_Last_Units_Scanned) >= 0.20
		then
			table.empty(tblPGetNearbyEnemies)
			table.empty(tblPGetMeleeEnemies)
			--table.empty(tblPEnemiesWithin16Yards)
			--table.empty(tblPEnemiesWithin12Yards)
			--table.empty(tblPEnemiesWithin10Yards)
			for x = 0, # ccrObjectListTable do
				local obj = ccrObjectListTable[x]
				if obj
				and obj:Exists()
				and not obj:IsDead()
				and	not tContains(tblObjectListIgnoreByName, obj:GetName())
				and not tContains(tblObjectListIgnoreByType, obj:GetCreatureInfo())
				and Player:CanAttack(obj)
				then
					local objDistance = Player:GetDistance(obj)
					if objDistance <= 44 then
						table.insert(tblPGetNearbyEnemies, obj)
					end
					--[[if objDistance <= 16 then
						table.insert(tblPEnemiesWithin16Yards, obj)
					end
					if objDistance <= 12 then
						table.insert(tblPEnemiesWithin12Yards, obj)
					end
					if objDistance <= 10 then
						table.insert(tblPEnemiesWithin10Yards, obj)
					end]]
					if objDistance <= 8 then
						table.insert(tblPGetMeleeEnemies, obj)
					end
				end
			end
		
			ccR_Last_Units_Scanned = GetTime()
		end
		ccR_Last_ObjectList_Scanned = GetTime()
	end
end

tbl_ccR_AutoLoot = {}
vLastAutoLootInteract = 0.1
function ccR_AutoLoot()
	if ccRS.Auto_Loot
	and not ccrPlayerIsCastingOrChanneling()
	and GetNumLootItems() == 0	
	and (not ccrPlayerIsInCombat() or (ccrPlayerIsInCombat() and #tblPGetMeleeEnemies == 0 and not ccrPlayerIsRanged()))
	and not bPauseAutoLoot
	and not ccrPlayerIsInCombat()
	and not ccrPlayerIsMoving()
	then
		table.empty(tbl_ccR_AutoLoot)
		-- Gather anything lootable and store
		for i = 1, GetTotalObjects(TYPE_UNIT) do	
			local vUnit = IGetObjectListEntry(i)
			if vUnit
			and IExists(vUnit)
			and IIsLootable(vUnit)
			then
				table.insert(tbl_ccR_AutoLoot, vUnit)
			end
		end
		-- Only check if we actually have something to loot
		if # tbl_ccR_AutoLoot > 0
		and (GetTime()-vLastAutoLootInteract) > 1.0
		then
			for i = 1, # tbl_ccR_AutoLoot do
				local vUnit = tbl_ccR_AutoLoot[i]
				if GDistance(vUnit) <= max(5, (13 / 6) + GCombatReach(vUnit)) then
					IObjectInteract(vUnit)
					vLastAutoLootInteract = GetTime()
					return
				end
			end
		end
	end
end